{extend name="public/base"}

{block name="title"}就行天下-确认订单{/block}

{block name="style"}
<link rel="stylesheet" href="__STATIC__/home/css/index.css" />
{/block}

{block name="main"}
<div class="pageControl bg-f7">
    <div class="main-top"></div>
    <div class="msui_nav msui_navTop noBorder">
        <a class="msui_navTop-back" href="javascript:history.back();"><i class="micon-back"></i></a>
        <h1 class="msui_navTop-title">确认订单</h1>
        <a href="" class="msui_navTop-right msui_navTop-cnav"><i class="micon-cnav"></i></a>
    </div>

    {empty name="data.address"}
    <!--收货地址没有-->
    <div class="address weui-cell weui-cell_access">
        <div class="weui-cell__bd ">
            <p class="fs065">未添加收货地址,新建地址,以确保商品正常派送</p>
        </div>
        <div class="weui-cell__ft">

        </div>
    </div>
    {else /}
    <!--收货地址已有-->
    <a href="{:url('address/index', ['request' => 'order'])}" class="weui-cell weui-cell_access">
        <div class="weui-cell__hd">
            <img src="__STATIC__/home/images/address.png" alt="" style="width: .8rem;">
        </div>
        <div class="weui-cell__bd ">
            <P class="fs065"><span>{$data.address.linkman} </span> <span>{$data.address.mobile}</span></P>
            <p class="fs06 cl-8c8c">{$data.address.address}</p>
        </div>
        <div class="weui-cell__ft">

        </div>
    </a>
    {/empty}

    <div class="weui-cells " style="padding-bottom: 3rem">
        {volist name="data.product" id="vo"}
        <div class="pl mtop05">
            <div class="weui-cell">
                <div class="weui-cell__hd indentImg">
                    <img src="{$vo.logo}" alt="">
                </div>
                <div class="weui-cell__bd">
                    <p class="fs07">{$vo.name}</p>
                    <div class="my-flex1">
                        <p class="xx">
                            <!--满星星加class为 active-->
                            <span {gt name="vo.level" value="0"} class="active" {/gt}></span>
                            <span {gt name="vo.level" value="1"} class="active" {/gt}></span>
                            <span {gt name="vo.level" value="2"} class="active" {/gt}></span>
                            <span {gt name="vo.level" value="3"} class="active" {/gt}></span>
                            <span {gt name="vo.level" value="4"} class="active" {/gt}></span>
                        </p>
                        <span class="fs06 exclusive-count">{$vo.level}分</span>
                    </div>
                </div>
                <div class="weui-cell__ft">

                </div>
            </div>
            {volist name="vo.list" id="v"}
            <div class="pl">
                <div class="weui-cell confirmOrder" >
                    <div class="weui-cell__hd">
                        <img src="{$v.thumb}" alt="">
                    </div>
                    <div class="weui-cell__bd ">
                        <p class="fs06 listFont">{$v.product_name}</p>
                    </div>
                    <div class="weui-cell__ft fs06">

                    </div>
                </div>
                <div class="card_button cl-9999">
                    <p class="price fs065">￥<span class="buyButton_price">{$v.price}</span></p>
                    <!--<p>x1</p>-->
                    {neq name="request" value="cart"}
                    <p class="buyButton mtop01">
                        <button {eq name="v.num" value="1"} disabled="disabled" {/eq} class="subtract" type="button" data-cart-id="{$v.id}">-</button>
                        <span>{$v.num}</span>
                        <button class="add" type="button" data-cart-id="{$v.id}">+</button>
                    </p>
                    {else /}
                    <p>x{$v.num}</p>
                    {/neq}
                </div>
            </div>
            {/volist}
            <div class="weui-cells weui-cells_form remark">

                <div class="weui-cell noBorder">
                    <div class="weui-cell__bd">
                        <textarea class="weui-textarea bg-f0 order_msg" data-shop-id="{$vo.shop_id}" placeholder="备注信息,限50字" rows="1"></textarea>
                    </div>
                </div>
            </div>
        </div>
        {/volist}
        <div class="weui-cell weui-cell_access">
            <div class="weui-cell__bd ">
                <p class="fs065">服务方式</p>
            </div>
            <div class="weui-cell__ft fs06">
                <span class="cl-3333">上门送货</span>
            </div>
        </div>
        <div class="weui-cell weui-cell_access">
            <div class="weui-cell__bd ">
                <p class="fs065">商品金额</p>
            </div>
            <div class="weui-cell__ft fs06">
                <span class="cl-c40">￥<span class="total_price">{$data.total_price}</span></span>
            </div>
        </div>
        <!--<div class="weui-cell weui-cell_switch">-->
            <!--<div class="weui-cell__bd ">-->
                <!--<p class="fs065">使用琼露</p>-->
            <!--</div>-->
            <!--<div class="weui-cell__ft fs06">-->
                <!--<p class="cl-c40 mr03 judge-lu">无可用琼露</p>-->
                <!--&lt;!&ndash;有琼露&ndash;&gt;-->
                <!--<p class="cl-c40 mr03 judge-lu">每单限2000点琼露</p>-->
                <!--&lt;!&ndash;开开开关&ndash;&gt;-->
                <!--<p class="cl-c40 mr03 judge-lu"><span class="luCount">2</span>滴琼露抵现<span class="luCount-money"></span>元</p>-->
            <!--</div>-->
            <!--<div class="weui-cell__ft fs06">-->
                <!--<label for="switchCP-lu" id="switchCP-lu1"  class="weui-switch-cp">-->
                    <!--<input id="switchCP-lu"  class="weui-switch-cp__input" type="checkbox">-->
                    <!--<div class="weui-switch-cp__box"></div>-->
                <!--</label>-->
            <!--</div>-->
        <!--</div>-->
        <!--<div class="weui-cell weui-cell_access">-->
            <!--<div class="weui-cell__bd ">-->
                <!--<p class="fs065">使用优惠券</p>-->
            <!--</div>-->
            <!--<div class="weui-cell__ft fs06">-->
                <!--&lt;!&ndash;没有优惠券&ndash;&gt;-->
                <!--<span class="cl-c40 mr03 judge-coupon" style="display: none">无可用优惠券</span>-->
                <!--&lt;!&ndash;有优惠券&ndash;&gt;-->
                <!--<span class="cl-c40 mr03 judge-coupon">满50减10元</span>-->
            <!--</div>-->
            <!--<input type="hidden" class="coupon" value="0">-->
        <!--</div>-->
    </div>
    <div class="order-ok-btn_2 bg-fff">
        <div class="">
            <p class="cl-9999 fs06">共计: <span class="total_count">{$data.total_num}</span>件</p>
            <p class="fs065">总计: <span class="cl-c40">￥<i class="total_price">{$data.total_price}</i></span></p>
        </div>
        <a href="javascript:;" class="cl-f save_order">提交订单</a>
    </div>
</div>
<!--没有收货地址-->
<div id="noAddress" class="centerPopup weui-popup__container">
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="fs065 title">
            您还没有创建收货地址, 是否立即新建?
        </div>
        <div class="model-btn-two">
            <a href="javascript:;" class="close-popup">取消</a>
            <a href="{:url('address/index', ['request' => 'order'])}">新建</a>
        </div>
    </div>
</div>
{/block}

{block name="javascript"}
<script>
    $('.address').click(function () {
        $('#noAddress').popup();
    });
    $(function () {
//    button是否可以点击
        if ($('.judge-lu').html()=='无可用琼露'){
            $('#switchCP-lu').attr('disabled','disabled');
        }else{
            $('#switchCP-lu').removeAttr('disabled');
        }
        $('.luCount-money').html($('.luCount').html()*.1);
        $('.buyButton button.subtract').click(function () {
            var t=$(this).next().html();
            if(t>2){
                t-=1;
            }else if(t=2){
                t=1;
                $(this).attr('disabled','disabled')
            }
            var _this = $(this);
            $.showLoading();
            $.post('{:url("cart/edit_num")}', {id: $(this).data('cart-id'), num : t}, function (msg) {
                if (msg.code == 200) {
                    _this.next().html(t);
                    total();
                } else {
                    $.hideLoading();
                    $.toptip(msg.msg);
                }
            }, 'json');
        });
        $('.buyButton button.add').click(function () {
            var t=parseFloat($(this).prev().html());
            t+=1;
            $('.buyButton button.subtract').removeAttr('disabled','disabled')
            var _this = $(this);
            $.showLoading();
            $.post('{:url("cart/edit_num")}', {id: $(this).data('cart-id'), num : t}, function (msg) {
                if (msg.code == 200) {
                    _this.prev().html(t);
                    total();
                } else {
                    $.hideLoading();
                    $.toptip(msg.msg);
                }
            }, 'json');
        });
        //    结算数量，价格
        function total() {
            $.loading_hide();
            var price=parseFloat($('.buyButton_price').html());
            var count=$('.buyButton span').html();
            $('.total_count').html(count);
            $(".total_price").html(number_format(roundNumber(price*count,2)));
        }

        $(".save_order").click(function () {
            $.showLoading('正在提交');
            var _address_id = '{$data.address.id|default="0"}';
            if (_address_id == 0) {
                $.toptip('请选择收货地址');
                $.hideLoading();
                return false;
            }
            var _ids = '{$data.cart_ids}';

            var order_msg = {};
            $(".order_msg").each(function (i, d) {
                var _shop_id = $(this).data('shop-id');
                order_msg['shop_id_' + _shop_id] = $(this).val();
            });

            $.ajax({
                type : 'POST',
                url : '{:url("create_order")}',
                data : {
                    cart_id : _ids,
                    address : _address_id,
                    shop_msg : order_msg,
                    use_integral : $('#switchCP-lu').prop('checked') ? 1 : 0,
                    coupon_id : $(".coupon").val()
                },
                dataType : 'json',
                success : function (msg) {
                    $.hideLoading();
                    if (msg.code == 200) {
                        $.toptip('提交成功', 'success');
                        window.location.href = "{:url('pay')}?model=order&id=" + msg.data.order_id;
                    } else {
                        $.toptip(msg.msg);
                    }
                    console.log(msg);
                }
            });
        });
    });
</script>
{/block}